﻿using Microsoft.EntityFrameworkCore;
using MilkTeaMachine.OfflineClient.EntityFrameworkCore.Models;

namespace MilkTeaMachine.OfflineClient.EntityFrameworkCore;

public class ApplicationDbContext : DbContext
{
    public DbSet<Formula> Formulas { get; set; }
    public DbSet<FormulaIngredient> FormulaIngredients { get; set; }
    public DbSet<Ingredient> Ingredients { get; set; }

    public ApplicationDbContext()
    {
    }

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Formula>()
            .Property(p => p.Id)
            .ValueGeneratedOnAdd();
        modelBuilder.Entity<FormulaIngredient>()
            .Property(p => p.Id)
            .ValueGeneratedOnAdd();
        modelBuilder.Entity<Ingredient>()
            .Property(p => p.Id)
            .ValueGeneratedOnAdd();
        modelBuilder.Entity<Formula>()
            .HasKey(p => p.Id);
        modelBuilder.Entity<FormulaIngredient>()
            .HasKey(p => p.Id);
        modelBuilder.Entity<Ingredient>()
            .HasKey(p => p.Id);
    }
}